package externaldata.passageTrainTheorique;

import java.util.Date;


public class PassageTrainTheorique implements Comparable<PassageTrainTheorique> {

	private int id;
	private String numeroTrain;
	private String nomTrain;
	private String gareDua;
	private String destinationUic;
	private Date arriveeTheorique;
	private boolean aUnPari;
	private String reseauTrain;
	
	
	public PassageTrainTheorique(PassageTrainTheorique pttToCopy) {
		this(pttToCopy.id, pttToCopy.numeroTrain, pttToCopy.nomTrain,
				pttToCopy.gareDua, pttToCopy.destinationUic, pttToCopy.arriveeTheorique,
				pttToCopy.aUnPari, pttToCopy.reseauTrain);
	}
	
	public PassageTrainTheorique() {
		this(0, null, null, null, null, null, false, null);
	}
	
	public PassageTrainTheorique(String numeroTrain, String gareDua,
			Date arriveeTheorique, String reseauTrain) {
		this(0, numeroTrain, null, gareDua, null, arriveeTheorique, false, reseauTrain);
	}

	public PassageTrainTheorique(String numeroTrain, String nomTrain,
			String gareDua, String destinationUic, Date arriveeTheorique,
			boolean aUnPari, String reseauTrain) {
		this(0, numeroTrain, nomTrain, gareDua, destinationUic, arriveeTheorique, aUnPari, reseauTrain);
	}

	public PassageTrainTheorique(int id, String numeroTrain, String nomTrain,
			String gareDua, String destinationUic, Date arriveeTheorique,
			boolean aUnPari, String reseauTrain) {
		this.id = id;
		this.numeroTrain = numeroTrain;
		this.nomTrain = nomTrain;
		this.gareDua = gareDua;
		this.destinationUic = destinationUic;
		this.arriveeTheorique = arriveeTheorique;
		this.aUnPari = aUnPari;
		this.reseauTrain = reseauTrain;
	}
	


	public int getId() {
		return id;
	}

	public void setId(int id) {
		if (id >= 0)
			this.id = id;
	}

	public String getNumeroTrain() {
		return numeroTrain;
	}

	public void setNumeroTrain(String numeroTrain) {
		if (numeroTrain != null && !numeroTrain.trim().equals(""))
			this.numeroTrain = numeroTrain.trim();
	}

	public String getNomTrain() {
		return nomTrain;
	}

	public void setNomTrain(String nomTrain) {
		// Ce champs peut être NULL
		if (nomTrain == null || !nomTrain.trim().equals(""))
			this.nomTrain = nomTrain == null ? null : nomTrain.trim();
	}

	public String getGareDua() {
		return gareDua;
	}

	public void setGareDua(String gareDua) {
		if (gareDua != null && !gareDua.trim().equals(""))
			this.gareDua = gareDua.trim();
	}

	public String getDestinationUic() {
		return destinationUic;
	}

	public void setDestinationUic(String destinationUic) {
		// Ce champs peut être NULL
		if (destinationUic == null || !destinationUic.trim().equals(""))
			this.destinationUic = destinationUic == null ? null : destinationUic.trim();
	}

	public Date getArriveeTheorique() {
		return arriveeTheorique;
	}

	public void setArriveeTheorique(Date arriveeTheorique) {
		if (arriveeTheorique != null)
			this.arriveeTheorique = arriveeTheorique;
	}

	public boolean getAUnPari() {
		return aUnPari;
	}

	public void setAUnPari(boolean aUnPari) {
		this.aUnPari = aUnPari;
	}
	
	public String getReseauTrain() {
		return reseauTrain;
	}
	
	public void setReseauTrain(char lineCode) {
		if (lineCode == 'A' 
				|| lineCode == 'B' 
				|| lineCode == 'C' 
				|| lineCode == 'D' 
				|| lineCode == 'E'
			)
			this.reseauTrain = "RER " + lineCode;
		else if (lineCode == 'H'
					|| lineCode == 'J'
					|| lineCode == 'K'
					|| lineCode == 'L'
					|| lineCode == 'N'
					|| lineCode == 'P'
					|| lineCode == 'R'
					|| lineCode == 'U'
				)
			this.reseauTrain = "Transilien " + lineCode;
	}

	
	
	/** 
	 * Compare les champs récupérables dans le fichier des horaires de passages théoriques
	 */
	@Override
	public boolean equals(Object o) {
		
		PassageTrainTheorique pttToCompareWith = (PassageTrainTheorique)o;
		
		return this.numeroTrain.equals(pttToCompareWith.numeroTrain) &&
				this.nomTrain.equals(pttToCompareWith.nomTrain) &&
				this.gareDua.equals(pttToCompareWith.gareDua) &&
				this.arriveeTheorique.getTime() == pttToCompareWith.arriveeTheorique.getTime();
	}


	@Override
	public int compareTo(PassageTrainTheorique ptt) {
		return this.arriveeTheorique.compareTo(ptt.arriveeTheorique);
	}
}
